const mongoose = require('mongoose');
require('./../models/typeModel');
require('./../models/exerciseModel');
require('./../models/pointModel');
const { testModel } = require('./../models/testModel');

module.exports.getTests = async function(req,res) {
    const result = await mongoose.model(testModel).find().populate("typeId").populate({
        path: 'exercisesId',
        populate: {
            path: 'pointId'
        }
    });
    // console.log(result)
    if(result){
        res.send({
            code: 1,
            message: '试卷信息获取成功',
            result: result
        });
    }else{
        res.send({
            code: 0,
            message: '用户信息获取失败'
        })
    }
}   

module.exports.getOneTests = async function(req,res) {
    console.log(req.body.id)
    const result = await mongoose.model(testModel).find({_id:req.body.id}).populate("typeId").populate({
        path: 'exercisesId',
        populate: {
            path: 'pointId'
        }
    });
    console.log(result)
    if(result){
        res.send({
            code: 1,
            message: '试卷信息获取成功',
            result: result[0]

        });
    }else{
        res.send({
            code: 0,
            message: '用户信息获取失败'
        })
    }
}